package 购物;

import java.util.ArrayList;

public class shopcar {
    private int capacity;
    private String[] list;
    public shopcar(int capacity, String[] list) {
        this.capacity = capacity;
        this.list = list;
    }
    private ArrayList<product> shoppcar;

    public shopcar() {
        this.shoppcar = new ArrayList<>();
    }
    public int getCapacity() {
        return capacity;
    }
    public void setCapacity(int capacity) {
        this.capacity = capacity;
    }
    public String[] getList() {
        return list;
    }
    public void setList(String[] list) {
        this.list = list;
    }

    public void addproduct(product product,int addnumber) {
        
        for (product p : shoppcar) {
            if (p.getName().equals(product.getName())) {
               
                p.setNumber(p.getNumber() + addnumber);
                return;
            }
        }
    }
        public double Total() {
            double sum = 0;
            for (product p : shoppcar) {
                sum+= p.getPrice() * p.getNumber();
            }
            return sum;
        }
    }


